# coding:utf-8

from gensim.models import KeyedVectors

class CW2Vec:

    def __init__(self,path):

        self.path = path
        self.model = KeyedVectors.load_word2vec_format(path,binary=False)


    def get_most_similar(self,words):
        print('与',words,'最相近的是:\n')
        for key in self.model.most_similar(words):
            print(key)

    def get_similarity(self,w1,w2):
        print(self.model.similarity(w1,w2))


if __name__ == '__main__':

    path = './datasets/embeddings-317084675-final-save.txt'
    model = CW2Vec(path)
    while(1):
        print('请输入词汇:')
        words = input()
        #w2 = input()
        if words == '' or words.isspace():
            break
        else:
            try:
                model.get_most_similar(words)
            #model.get_similarity(words,w2)
            except Exception as e:
                print(e)